package dao

import (
	"yundian/internel/app/helper/request"
	"yundian/internel/app/models/ratingsetting"
	"yundian/internel/pkg/dingo"
	"yundian/internel/pkg/dingo/global"
)

//-----提现配置

//提现配置列表
func (d *SiteSettingDao) RatingSettingListDao(baseListReq *request.BaseListReq) *dingo.ErrorWrap {

	var (
		lst    []ratingsetting.RatingSetting
		count  int64
		limit  = baseListReq.PageSize
		offset = baseListReq.PageSize * (baseListReq.PageNo - 1)
	)
	db := global.Orm.Table("rating_setting")
	db.Limit(limit).Offset(offset).Find(&lst).Limit(-1).Offset(-1).Count(&count)
	return dingo.ErrorIf(db.Error, lst, count)
}

//提现配置编辑
func (d *SiteSettingDao) RatingSettingEditDao(id int, m *ratingsetting.RatingSetting) *dingo.ErrorWrap {

	db := global.Orm.Table("rating_setting")
	db.Where("id = ?", id)
	db.Model(&m)
	db.Updates(&m)
	if db.Error != nil {
		return dingo.ErrorIf(db.Error, false)
	}

	return dingo.ErrorIf(db.Error, true)
}

//提现配置保存
func (d *SiteSettingDao) RatingSettingSaveDao(param *ratingsetting.RatingSetting) *dingo.ErrorWrap {

	db := global.Orm.Table("rating_setting")
	db.Create(&param)
	return dingo.ErrorIf(db.Error, true)
}

//提现配置删除
func (d *SiteSettingDao) RatingSettingDeleteDao(id int) *dingo.ErrorWrap {
	db := global.Orm.Exec("delete from rating_setting where id = ?", id)
	return dingo.ErrorIf(db.Error, true)
}

//查询提现类型是否存在
func (d *SiteSettingDao) GetRatingSetting(rating string) *dingo.ErrorWrap {
	model := ratingsetting.RatingSetting{}
	db := global.Orm.Table("rating_setting").Where("rating = ?", rating).Find(&model)
	if db.RowsAffected > 0 {
		return dingo.ErrorIf(db.Error, false)
	}
	return dingo.ErrorIf(db.Error, true)
}
